#ifndef __RENDERMANAGER_H__
#define __RENDERMANAGER_H__

#include "Ogre.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../resource/res/resource.h"
#endif


/**
 *	RenderManager initialises Ogre3D render and game render window.
 *	Accessor return pointers to both Ogre Root and render window which is initialised by Ogre.
 *	This class has inherited function from Ogre FrameListener. This will provide WHILE LOOP control
 *	for the game. Classes that require updates are added to the FrameListener.
 */

class RenderManager : public Ogre::FrameListener
{
private:	// Attributes
	Ogre::Root						*m_pRoot;				/**< Ogre root pointer. */
	Ogre::RenderWindow				*m_pRenderWindow;		/**< Ogre render window pointer. */
	unsigned long					m_hWnd;					/**< Handler to the ogre render window. */
	bool							m_bStatsOn;				/**< Stats display. */
	Ogre::TextureFilterOptions		m_Filtering;			/**< Texture filtering mode. */
	int								m_iAniso;				/**< Anisotrophic level. */
	bool							m_ShutDownRequested;	/**< Shutdown call. */

	static RenderManager			*renderMgr;				/**< Static pointer to self. */

private:	// Functions
	/**
	 *	Constructor function calls setup() function to initialise render manager.
	 **/
	RenderManager(void);	// private ctor for singleton class

	/**
	 *	Implementation of initialisation of Ogre Root and Ogre plugins
	 */
	void initialise(void);

	/**
	 *	Resource setup. Calls Ogre resource manager to manage all resources required for the 
	 *	game.
	 */
	void setupResources(void);

	/**
	 *	Creates and handles the render window.
	 */
	void createWindow(void);

	/**
	 *	Runs through all initial functions to start RenderManager
	 */
	bool setup(void);

	/**
	 *	Adds this manager class to Ogre FrameListener.
	 */
	void createFrameListener(void);

public:
	/**
	 *	RenderManager destructor.
	 *	TODO: Add clean up implementation
	 */
	~RenderManager(void);

	/**
	 *	Singleton access function for RenderManager.
	 */
	static RenderManager* getSingleton(void);

	/**
	 *	Cleaner for RenderManager. Cleans all pointers to Ogre render system.
	 */
	void cleanup(void);

	/**
	 *	Calls ogre root start rendering function. Renders frames.
	 */
	void startRendering(void);

	/**
	 *	Function called by the Ogre Framelister. Updates occur in these functions.
	 *	Updates taken on frame start.
	 *	@param &evt Pointer to Ogre FrameEvent
	 *	@return bool - Tells the frame listener to exit loop.
	 */
	bool frameStarted(const Ogre::FrameEvent& evt);

	/**
	 *	Function called by the Ogre Framelister. Updates occur in these functions.
	 *	Updates taken on frame end.
	 *	@param &evt Pointer to Ogre FrameEvent
	 *	@return bool - Tells the frame listener to exit loop.
	 */
	bool frameEnded(const Ogre::FrameEvent& evt);

	// accessors
	/**
	 *	Gets the handle to the render window.
	 *	@return unsigned long
	 */
	unsigned long getWindowsHandle(void){ return m_hWnd; };

	/**
	 *	Returns ogre root pointer.
	 *	@return Root
	 */
	Ogre::Root* getRoot(void){ return m_pRoot; };	
	
	/**
	 *	Returns pointer to ogre render window.
	 *	@return RenderWindow
	 */
	Ogre::RenderWindow* getRenderWindow(void){ return m_pRenderWindow; };	// Returns render window pointer

};
	
	

#endif